<template>
  <el-container>
    <!-- 头部区域 -->
    <el-header>
      <img src="../assets/logo.png" class="logo"/>
      <el-button type="primary" round size="mini" class="logOut" @click="logOut">退出</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 测边栏 -->
      <el-aside :width="unfold?'64px':'200px'">
        <div class="left_button" @click="unfoldFun"><div>|||</div></div>
        <!-- 侧边栏菜单区域 -->
        <el-menu :unique-opened="true" class="el-menu-vertical-demo" background-color="#545c64" :default-active="active"
          text-color="#fff" active-text-color="rgb(64, 158, 255)" router :collapse="unfold" :collapse-transition="false">
          <!-- 一级菜单 -->
          <el-submenu :index="item.path" v-for="item in menus" :key="item.id">
            <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconObj[item.id]"></i>
              <!-- 文本 -->
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="childItem.path" v-for="childItem in item.children" :key="childItem.id">
              <i class="el-icon-menu"></i>
              <span>{{childItem.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<style>
  .el-container {overflow: hidden;}
  html,body,#app,.el-container {height:100%;}
  .el-header {
    background-color: #545c64;
    color: #fff;
    line-height: 60px;
  }
  aside.el-aside {
    height: 100%;
    background: rgb(84, 92, 100);
    transition: all 0.3s ease-in-out;
    padding-bottom: 0;
  }
  .logo {float: left;padding:16px 0}
  .he_right {float: right;color:#fff;}
  .he_right i.el-icon-s-custom {margin-right: 10px;}
  .logOut {float: right;position: relative;top: 16px;}
  .el-menu {border:0;}
  .left_button {position: relative;width: 100%;background: #444;cursor: pointer;text-align: center;padding: 8px 0;}
  .left_button div {
    transform: rotate(90deg);
    letter-spacing: 1px;
    color:#fff;
    opacity: 0.8;
    text-align:center;
  }
  .el-submenu {text-align: left;}
  .el-submenu__title i {color:#fff;margin-right:10px;opacity: 0.8;padding-left:4px;}
</style>

<script>
export default {
  data () {
    return {
      menus: [], // 左测列表
      unfold: false, // 左侧展开开关
      iconObj: { // 菜单图标
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      active: '/users'
    }
  },
  mounted: async function () {
    const { data: res } = await this.$http.get('menus') // 调用左侧菜单数据
    this.menus = res.data
  },
  methods: {
    logOut: function () { // 退出登陆
      this.$router.push('/logIn')
      sessionStorage.clear()
    },
    unfoldFun () { // 左侧菜单展收
      this.unfold = !this.unfold
    }
  }
}
</script>
